package com.blog.system.api.factory;

import com.blog.common.core.domain.R;
import com.blog.common.domain.entity.SiteConfig;
import com.blog.system.api.feign.RemoteConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 配置服务降级处理
 * </p>
 *
 * @author Valerie
 * @date 2023/4/15
 **/
@Slf4j
@Component
public class RemoteConfigFallbackFactory implements FallbackFactory<RemoteConfigService> {

    @Override
    public RemoteConfigService create(Throwable cause) {
        return new RemoteConfigService() {
            @Override
            public R<SiteConfig> getWebsiteConfig() {
                log.error("配置服务调用失败：" + cause.getMessage());
                return R.fail("配置服务调用失败：" + cause.getMessage());
            }

            @Override
            public R<Void> saveSitePageCover() {
                log.error("配置服务调用失败：" + cause.getMessage());
                return R.fail("配置服务调用失败：" + cause.getMessage());
            }
        };
    }
}
